/**
 * 增删改访客
 */
package com.kerrykidz.membership.controller;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.kerrykidz.filemanagement.service.ISalesService;
import com.kerrykidz.filemanagement.service.IVipService;
import com.kerrykidz.membership.dao.model.CusGuaEntity;
import com.kerrykidz.membership.dao.model.CusMemEntity;
import com.kerrykidz.membership.dao.model.GblCusCReltypeEntity;
import com.kerrykidz.membership.service.IGuaService;
import com.kerrykidz.membership.service.IMemberService;
import com.kerrykidz.system.dao.model.GblCusCCountryEntity;
import com.kerrykidz.system.dao.model.SecUsrEntity;
import com.kerrykidz.system.service.IGblService;
import com.rdp.framework.exception.RDPException;

/**
 * @author Tik
 * 
 */
@RequestMapping("membership/visitor")
@Controller
public class MemberVisitorController {

	@Autowired
	private IMemberService memberService;
	@Autowired
	private IGuaService guaService;
	@Autowired
	private IVipService vipService;
	@Autowired
	private ISalesService salesService;
	@Autowired
	private IGblService gblService;


	/**
	 * 跳转到访客界面
	 * 
	 * @return
	 * @throws RDPException 
	 */
	@RequestMapping("/jumpVisitor")
	public ModelAndView jumpVisitor() throws RDPException {

		ModelAndView mv = new ModelAndView("membership/membership_visitor_detail");
		
		List<GblCusCReltypeEntity> reltypeList = memberService.findReltypes();
		mv.addObject("reltypeList", reltypeList);

		// 销售列表
		List<SecUsrEntity> salesList = salesService.listSales();
		mv.addObject("salesList", salesList);

		// 国籍列表
		List<GblCusCCountryEntity> countryList = gblService.selectAll();
		mv.addObject("countryList", countryList);
		return mv;
	}

	/**
	 * 查询会员及其关联信息
	 * 
	 * @param memberId
	 *                会员编号
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/queryMemberDetail")
	public ModelAndView queryMemberDetail(@RequestParam(value = "memberId", required = false) String memberId) throws RDPException {

		ModelAndView mv = new ModelAndView("membership/membership_visitor_detail");

		if (StringUtils.isNotBlank(memberId)) {
			// 会员、非会员信息 兄弟姐妹
			List<CusMemEntity> memList = memberService.findMemberAndSiblingsById(memberId);
			mv.addObject("memList", memList);
			if (memList.size() > 0) {
				mv.addObject("familyId", memList.get(0).getFamilyId());
			}
			mv.addObject("memberId", memberId);

			// 监护人列表
			List<CusGuaEntity> guaList = memberService.findGuaByMemberId(memberId);
			mv.addObject("guaList", guaList);

		}

		//关系列表
		List<GblCusCReltypeEntity> reltypeList = memberService.findReltypes();
		mv.addObject("reltypeList", reltypeList);

		// 销售列表
		List<SecUsrEntity> salesList = salesService.listSales();
		mv.addObject("salesList", salesList);

		// 国籍列表
		List<GblCusCCountryEntity> countryList = gblService.selectAll();
		mv.addObject("countryList", countryList);

		return mv;

	}

}
